#!/bin/bash

for i in `kubectl top node|grep -v unknown|awk '{if ($5 > 80) print $1}'`
do
    podname=`kubectl get pod -A -owide|grep $i|awk '{print $2}'`
    kubectl top pod --all-namespaces --no-headers=true --sort-by=memory|grep -v rook-ceph|grep -v default|grep -v keda|grep -v kube-system|grep -v monitoring|grep -v istio-system|grep -v public-service|grep -v cattle-fleet-system|grep -v kubernetes-dashboard|grep -v logging|grep -v allure-docker-service|
    kubectl delete pod $podname -n monitoring
    sleep 240s
done
